package com.wishwall.beans;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonProperty;

@Entity
@Table(name="TM_USER_ROLE")
public class UserRoleMappingBean implements Serializable {


	private static final long serialVersionUID = 1577366767747040960L;

	@Id
	@Column(name="TM_USER_ROLE_PK")
	private Integer id;

	@Column(name="USER_FK")
	private Integer userId;
	
	@ManyToOne(cascade={CascadeType.DETACH})
	@JoinColumn(name="USER_ROLE_FK")
	private UserRoleBean userRole;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public UserRoleBean getUserRole() {
		return userRole;
	}

	public void setUserRole(UserRoleBean userRole) {
		this.userRole = userRole;
	}	
	

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}	
	
	@JsonProperty
	public String getRoleName() {
		return userRole.getName();
	}	
	
	@JsonProperty
	public String getRoleDisplayName() {
		return userRole.getDisplayName();
	}	
	
	@Override
	public int hashCode() {
		if (this.id != null) {
			return this.id.hashCode();
		} else {
			return super.hashCode();
		}
	}

	@Override
	public boolean equals(Object obj) {
		
		if (obj == null) {
			return false;
		}
		
		if (!(obj instanceof UserRoleMappingBean)) {
			return false;
		}
		
		if (this == obj) {
			return true;
		}
		
		UserRoleMappingBean other = (UserRoleMappingBean) obj;
		if ((id == null) || (other.getId() == null)) {
			return false;
		}
		
		return (id.equals(other.getId()));
	}

	
	
}
